# include <future>
# include "threadpool.h"
using namespace std;

/*
 * 1.如何让线程池提交任务更方便
 *   pool.submitTask(sum1, 10, 20);
 *   pool.submitTask(sum2, 10, 20, 30);
 *   submitTask:可变参模板编程
 *
 * 2.使用packaged_task与async来代替result获取Thread的返回值
 *   使用future代替result减少线程池代码
 */

int sum1 (int a, int b) {
    return a + b;
}


int main() {
    ThreadPool pool;
    pool.setMode(PoolMode::MODE_CACHED);
    pool.start(1);
    future<int> r1 = pool.submitTask(sum1, 1, 2);
    future<int> r2 = pool.submitTask([](int a, int b)->int{return a*b;}, 2, 3);
    cout << r1.get() << endl;
    cout << r2.get() << endl;
//    packaged_task<int(int, int)> task(sum1);
//    future<int> res = task.get_future();
//    task(10, 20);
//    thread t(move(task), 10, 20);
//    t.detach();
//    cout << res.get() << endl;
//    return 0;
}
